package com.lkd.mapper;

import com.lkd.annotation.AutoFill;
import com.lkd.dto.PartnerPageDto;
import com.lkd.entity.Partner;
import com.lkd.vo.PartnerVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PartnerMapper {
    //新增合作商
    @AutoFill("insert")
    @Insert("INSERT INTO lkdremake.tb_partner (name, password, account, mobile, phone, email, province, city, county, addr, contact, ratio, status, create_time, update_time) " +
            "VALUES (#{name}, #{password}, #{account}, #{mobile}, #{phone}, #{email}, #{province}, #{city}, #{county}, #{addr}, #{contact}, #{ratio}, #{status}, now(), now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Boolean save(Partner partner);


    //分页查询合作商
    List<PartnerVo> getPage(PartnerPageDto partnerPageDto);

    @Select("select count(*) vmCount from lkdremake.tb_partner p left join tb_vending_machine vm on p.id=vm.owner_id WHERE p.id=#{id} ")
    Integer getVmCount(Integer id);

    //根据ID查询合作商
    @Select("select * from lkdremake.tb_partner WHERE id=#{id} ")
    Partner getById(Integer id);

    //根据ID修改合作商
    @AutoFill("update")
    Boolean update(Partner partner);

    //根据ID删除合作商
    @Select("DELETE FROM lkdremake.tb_partner WHERE id=#{id}")
    Boolean deleteById(Integer id);

    //查询合作商总数
    @Select("select count(*) from lkdremake.tb_partner")
    Integer count();
}
